package jdbc2;

import org.junit.Test;

/**
 * Created by kevin on 2020/3/30.
 */
public class Demo1 {
    private AccountDao dao = new AccountDao();
    @Test
    public void ServiceMethod(){
        try {
            //事务连接不会被关闭
            JdbcUtils.beginTransaction();
            dao.update("zs",10000);
            if(true)throw new RuntimeException("出异常了,给我回滚!");//事务测试
            dao.update("ls",-10000);
            JdbcUtils.commitTransaction();
        } catch (Exception e) {
            try {
                JdbcUtils.rollbackTransaction();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            throw e;
        }
    }
}
